﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System
{
    /// <summary>
    /// 针对<see cref="IServiceProvider"/>进行扩展
    /// </summary>
    public static class ServiceProviderExtensions
    {
        /// <summary>
        /// 尝试获取类型<typeparamref name="T"/>的脑出血
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static T TryGetService<T>(this IServiceProvider serviceProvider) where T : class
        {
            return serviceProvider.GetService(typeof(T)) as T;
        }
    }
}
